<?php

/**
 * This is the model class for table "tbl_connections".
 *
 * The followings are the available columns in table 'tbl_connections':
 * @property integer $connection_id
 * @property integer $member_id
 * @property integer $friendship_id
 * @property integer $who_requested
 * @property integer $is_blocked
 * @property integer $is_confirmed
 * @property string $date_request
 * @property string $date_confirmed
 *
 * The followings are the available model relations:
 * @property TblMember $friendship
 * @property TblMember $member
 */
class Connections extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Connections the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_connections';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('date_request, date_confirmed', 'required'),
			array('member_id, friendship_id, who_requested, is_blocked, is_confirmed', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('connection_id, member_id, friendship_id, who_requested, is_blocked, is_confirmed, date_request, date_confirmed', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'friendship' => array(self::BELONGS_TO, 'TblMember', 'friendship_id'),
			'member' => array(self::BELONGS_TO, 'TblMember', 'member_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'connection_id' => 'Connection',
			'member_id' => 'Member',
			'friendship_id' => 'Friendship',
			'who_requested' => 'Who Requested',
			'is_blocked' => 'Is Blocked',
			'is_confirmed' => 'Is Confirmed',
			'date_request' => 'Date Request',
			'date_confirmed' => 'Date Confirmed',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('connection_id',$this->connection_id);
		$criteria->compare('member_id',$this->member_id);
		$criteria->compare('friendship_id',$this->friendship_id);
		$criteria->compare('who_requested',$this->who_requested);
		$criteria->compare('is_blocked',$this->is_blocked);
		$criteria->compare('is_confirmed',$this->is_confirmed);
		$criteria->compare('date_request',$this->date_request,true);
		$criteria->compare('date_confirmed',$this->date_confirmed,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}